<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

include 'includes/gzip.php';

include 'includes/toolbar.php';
include 'includes/config.php';
include 'includes/functions.php';
include 'includes/database.php';
include 'includes/orm.php';
include 'includes/models.php';

new Db();

$page = $_GET['page'];
$type = $_GET['type'];
$action = $_GET['action'];
$cid = $_GET['cid'];
$uid = $_GET['uid'];

$alert = array("error"=>0, "error_msg"=>"");

include_once 'header_controller.php';
start_component();

switch($page){
	case "bookings":
		include_once 'bookings_controller.php';
		switch($_POST['form']){
			case "filter":
				filter_bookings();
				break;
			case "new_booking":
				save_booking();
				break;
			case "edit_booking":
				save_edit_booking($_GET['bid']);
				break;
			case "delete_items":
				delete_selected_bookings();
				break;
			case "set_items_confirmed":
				set_items_confirmed();
				break;
			default:
				break;
		}
		show_notice();
		switch($_GET['action']){
			case "new":
				new_booking();
				break;
			case "edit":
				$bid = $_GET['bid'];
				show_edit_booking($bid);
				break;
			default:
				show_bookings();
				break;
		}
		break;
	case "customers":
		include_once 'customer_controller.php';
		switch($_POST['form']){
			case "create_or_edit_customer":
				save_customer();
				break;
			case "search_customers":
				search_customers();
				break;
			case "delete_items":
				delete_selected_customers();
				break;
		}
		show_notice();
		switch($_GET['action']){
			case "new":
				new_customer();
				break;
			case "edit":
				edit_customer();
				break;
			default:
				switch($_GET['group']){
					case "managers":
						show_managers();
						break;
					case "guests":
						show_guests();
						break;
					case "all":
						show_all();
						break;
					default:
						show_all();
						break;
				}
				break;
		}
		break;
	case "managers":
		include_once 'customer_controller.php';
		show_manager_details();
		break;
	case "units":
		include_once 'units_controller.php';
		switch($_POST['form']){
			case "filter":
				filter_units();
				break;
			case "delete_items":
				delete_units();
				break;
			case "edit_units":
				if(!empty($_POST['upload_image_form'])) image_uploader();
				else save_edit_units();
				break;
			case "new_unit":
				save_new_unit();
				break;
			case "image":
				print_r($_POST);
				print_r($_FILES);
				break;
		}
		show_notice();
		if(empty($_POST['upload_image_form'])){
			switch($_GET['action']){
				case "new":
					new_unit();
					break;
				case "edit":
					show_edit_units();
					break;
				default:
					show_units();
					break;
			}
		}
		
		break;
	case "categories":
		include_once 'categories_controller.php';
		switch($_POST['form']){
			case "new_category":
				save_new_category();
				break;
			case "delete_items":
				delete_selected_categories();
				break;
		}
		show_notice();
		switch($_GET['action']){
			case "new":
				new_category();
				break;
			default:
				show_categories();
				break;
		}
		break;
	case "featured":
		include_once 'featured_controller.php';
		switch ($_POST['form']){
			case "set_items_published":
				set_items_published();
				break;
		}
		show_notice();
		show_featured();
		break;
	case "amenities":
		include_once 'amenities_controller.php';
		switch($_POST['form']){
			case "new_amenity":
				save_amenity();
				break;
			case "delete_items":
				delete_amenities();
				break;
		}
		show_notice();
		switch($_GET['action']){
			case "new":
				new_amenity();
				break;
			default:
				show_amenities();
				break;
		}
		break;
	case "configuration":
		include_once 'configuration_controller.php';
		switch($_POST['form']){
			case "save_letter":
				save_letter();
				break;
			case "general_config":
				save_config();
				break;
		}
		show_notice();
		switch($_GET['action']){
			case "set_letters":
				if(isset($_GET['lid'])) edit_letters();
				else if(isset($_GET['task']) && $_GET['task'] == "new") create_letters();
				else show_set_letters();
				break;
			case "general":
				show_general_config();
				break;
		}
		break;
	default:
		include_once 'views/dashboard.html.php';
		break;
}

switch($type){
	case "manager_details":
		include_once 'customer_controller.php';
		$cid;
		break;
	case "unit_details":
		include_once 'units_controller.php';
		include_once 'amenities_controller.php';
		include_once 'images_controller.php';
		include_once 'prices_controller.php';
		$uid;
		break;
}

switch($action){
	case "new":
		break;
}

end_component();
//$Db->close_connection();
?>